package com.tulingxueyuan.mall.modules.oms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tulingxueyuan.mall.common.api.CommonPage;
import com.tulingxueyuan.mall.common.api.CommonResult;
import com.tulingxueyuan.mall.modules.oms.model.OmsOrderReturnApply;
import com.tulingxueyuan.mall.modules.oms.model.dto.OmsOrderReturnApplyResultDTO;
import com.tulingxueyuan.mall.modules.oms.model.dto.OmsReturnApplyQueryParamDTO;
import com.tulingxueyuan.mall.modules.oms.model.dto.OmsUpdateStatusParamDTO;
import com.tulingxueyuan.mall.modules.oms.service.OmsOrderReturnApplyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单退货申请 前端控制器
 * </p>
 *
 * @author zhaofuhao
 * @since 2022-03-03
 */
@RestController
@RequestMapping("/returnApply")
public class OmsOrderReturnApplyController {
    @Autowired
    private OmsOrderReturnApplyService returnApplyService;

    /**
     *   return request({
     *     url:'/returnApply/list',
     *     method:'get',
     *     params:params
     *   })
     */
    @ApiOperation("分页查询退货申请")
    @GetMapping( "/list")
    @ResponseBody
    public CommonResult list(OmsReturnApplyQueryParamDTO queryParam) {
        Page page = returnApplyService.list(queryParam);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @ApiOperation("获取退货申请详情")
    @GetMapping(value = "/{id}")
    @ResponseBody
    public CommonResult getItem(@PathVariable Long id) {
        OmsOrderReturnApplyResultDTO result = returnApplyService.getItem(id);
        return CommonResult.success(result);
    }

    @ApiOperation("修改申请状态")
    @PostMapping(value = "/update/status/{id}")
    @ResponseBody
    public CommonResult updateStatus(@PathVariable Long id, @RequestBody OmsUpdateStatusParamDTO statusParam) {
        boolean count = returnApplyService.updateStatus(id,statusParam);
        if (count) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
    @ApiOperation("批量删除申请")
    @PostMapping(value = "/delete")
    @ResponseBody
    public CommonResult delete(@RequestParam("ids") List<Long> ids) {
        boolean count = returnApplyService.removeByIds(ids);
        if (count) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }



}

